<?php

namespace App\Kuafu\CustomerCoupon\Model;

use App\Kuafu\Base\Model\BaseModel;
use App\Kuafu\Base\Model\Traits\KfSoftDeletes;

class SendCustomerCouponFailLog extends BaseModel
{
    use KfSoftDeletes;

    protected $connection = 'mysql';
    protected $table      = 'customer_send_coupon_fail_logs';
    protected $primaryKey = 'id';

    protected $fillable   = [
        'userId',
        'activityId',
        'activityType',
        'createdAt'
    ];

    protected $hidden = [
        'updatedAt',
        'isDeleted'
    ];

    /**
     * 根据活动id获取失败的发放列表
     * @param $size
     * @param $activityId
     * @param $activityType
     * @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
     */
    public static function getFailList($size, $activityId, $activityType)
    {
        return self::query()
                   ->where(['activityId' => $activityId, 'activityType' => $activityType])
                   ->limit($size)
                   ->get();
    }

    /**
     * 添加失败数据
     * @param array $data
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model
     */
    public static function addData(array $data)
    {
        return self::query()->create($data);
    }

}
